package com.demo.webapp.ui.table;

import java.util.HashMap;
import java.util.Map;

import com.demo.webapp.ui.Component;

/**
 * Table组件中的Column组件容器
 * 
 * @author ryuu.kk
 * 
 */
public class ColumnComponent implements Component {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = 5597047542447789029L;
	/**
	 * 组件类型:table的column类型
	 */
	public static final String COMPONENT_TYPE_HEAD = "thead";
	/**
	 * 组件类型:table的column类型
	 */
	public static final String COMPONENT_TYPE_FOOT = "tfoot";
	/**
	 * 组件类型:table的column类型
	 */
	public static final String COMPONENT_TYPE_BODY = "tbody";
	
	/**
	 * HTML的column属性名：class
	 */
	public static final String ARRTIBUTE_CLASS = "class";
	
	/**
	 * HTML的column属性名: style
	 */
	public static final String ARRTIBUTE_STYLE = "style";
	
	// 唯一性标识
	private String id;
	// 组件名
	private String name;
	// 组件类型
	private String type = COMPONENT_TYPE_BODY;
	// 组件基础地址
	private String baseUri;
	//属性Map
	private Map<String, String> attributeMap;
	
	// ~附加信息 ：①、排序--------------------------------------------------
	private String sort;
	// column数据属性
    private String property;
    // column数据格式化字符串
    private String format;
    // column数据隐藏
    private String hidden;
    // column标题
    private String title;
    // column可以排序
    private boolean sortable;
    // column的样式class
    private String clazz;
    // table中head的class
    private String headerClass;
    // column中的值内容
    private String value;
    // column中包含的HTML代码
    private String innerHtml;
    // column中Head的HTML代码.如果为空,则使用column的一般性标题title或由模板决定
    private String headHtml;
    // column中Foot的HTML代码.如果为空,则使用column的一般性标题title或由模板决定
    private String footHtml;
	@Override
	public String getId() {
		return id;
	}

	@Override
	public String getUrl() {
		return getBaseUri();
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getType() {
		return type;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getBaseUri() {
		return baseUri;
	}

	public void setBaseUri(String baseUri) {
		this.baseUri = baseUri;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Map<String, String> getAttributeMap() {
		return attributeMap;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public String getHidden() {
		return hidden;
	}

	public void setHidden(String hidden) {
		this.hidden = hidden;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public boolean getSortable() {
		return sortable;
	}

	public void setSortable(boolean sortable) {
		this.sortable = sortable;
	}

	public String getColumnClass() {
		return clazz;
	}

	public void setColumnClass(String clazz) {
		this.clazz = clazz;
	}

	public String getHeaderClass() {
		return headerClass;
	}

	public void setHeaderClass(String headerClass) {
		this.headerClass = headerClass;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getInnerHtml() {
		return innerHtml;
	}

	public void setInnerHtml(String innerHtml) {
		this.innerHtml = innerHtml;
	}

	public void setUrl(String url) {
		this.baseUri = url;
	}

	public String getHeadHtml() {
		return headHtml;
	}

	public void setHeadHtml(String headerHtml) {
		this.headHtml = headerHtml;
	}

	public String getFootHtml() {
		return footHtml;
	}

	public void setFootHtml(String footHtml) {
		this.footHtml = footHtml;
	}

	public void setAttributeMap(Map<String, String> attributeMap) {
		this.attributeMap = attributeMap;
	}
	
	public void setAttribute(String key, String value) {
		if (attributeMap == null) {
			attributeMap = new HashMap<String, String>();
		}
		attributeMap.put(key, value);
	}
	public String getAttribute(String key) {
		if (attributeMap == null) {
			return "";
		}
		return attributeMap.get(key);
	}
}
